<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>列表</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css" />
    <link rel="stylesheet" href="/css/coupon/couponManage/couponList/coupon-list.css">
    <script src="/js/public/public.js"></script>
</head>
<body>
<div class="layui-row">
    <div class="layui-col-md12">
        <div class="list">
            <div class="list-left layui-col-md8">
                <div class="list-left-left"></div>
                <p class="list-left-right">前台用户登录列表</p>
            </div>
            <div class="list-right layui-col-md4">
                <div class="queryButtonBox">
                    <button class="list-right-left layui-btn" style="margin-top: 3px" onclick="refresh()">
                        <i class="layui-icon layui-icon-refresh"></i>&nbsp;刷新
                    </button>
                    <button class="list-right-right layui-btn" id="goBack" style="margin-top: 3px">
                        <i class="layui-icon layui-icon-left"></i>&nbsp;返回
                    </button>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-md12">
        <div class="layui-row query">
            <div class="layui-card headerCenter">
                <div class="layui-card-header backColor">
                    <i class="layui-icon">&#xe615;</i>
                    筛选查询
                </div>
                <div class="layui-card-body">
                    <form class="layui-form">
                        <div class="layui-form-item ">
                            <div class="layui-col-md4">
                                <label class="layui-form-label">用户账号：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="account" class="layui-input" layui-verify="required" required placeholder="请输入用户账号">
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <label class="layui-form-label">用户昵称：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="trueName" class="layui-input" layui-verify="required" required placeholder="请输入用户昵称">
                                </div>
                            </div>
                            <div class="layui-col-md4">
                                <div class="queryButtonBox">
                                    <button type="button" class="layui-btn" onclick="search()">
                                        <i class="layui-icon layui-icon-search"></i>&nbsp;搜索
                                    </button>
                                    <button type="reset" class="layui-btn layui-btn-warm">
                                        <i class="layui-icon layui-icon-refresh"></i>&nbsp;重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-col-md12">
        <!--数据列表-->
        <div class="record">
            <div class="record-right">
                <!--表-->
                <table id="demoTable" lay-filter="demoTable"></table>
            </div>
        </div>
        <!--表头样式-->
        <div class="tableHeader" style="display:none" id="tableHeader">
            <i class="layui-icon layui-icon-align-left"></i>优惠券列表
        </div>
        <!--表内操作-->
        <div id="button_caozuo" style="display:none" >
            <a alt="删除" title="删除"  lay-event="deleteTable" style="color:green;">删除</a>
        </div>
    </div>
</div>
<script>
    layui.use(['jquery','layer','table','form'],function(){
        var $=layui.jquery;
        var layer=layui.layer;
        var table=layui.table;
        var form=layui.form;

        refresh=function refresh(){
            location.reload();
        }

        getTable('','');

        search=function search(){
            var account=$("input[name=account]").val();
            var trueName=$("input[name=trueName]").val();
            getTable(account,trueName);
        }

        function getTable(account,trueName){
            var param={
                'account':account,
                'trueName':trueName,
                'loginType':3
            }
            $.ajax({
                url:"/login/getBackStageLogin",
                type:"post",
                dataType:"json",
                data:param,
                success:function (data) {
                    demoTable(data.data);
                }
            })
        }

        function demoTable(data) {
            table.render({
                elem: '#demoTable',
                title: "前台用户登录列表",
                data: data,
                toolbar: '#tableHeader',
                limit: 10,
                page: {
                    layout: ['count', 'prev', 'page', 'next', 'limit', 'skip', 'refresh'],
                    limits: [10, 20, 30],
                    first: "首页",
                    last: "尾页",
                },
                cols:[[
                    {type:'checkbox'},
                    {title: '序号',align:'center', templet: function (data) {
                            return data.LAY_INDEX;
                        }},
                    {field:"loginAddress",title:"登录地址",align:"center"},
                    {field:"loginIp",title:"登录ip",align:"center"},
                    {field:"loginState",title:"登录状态",align:"center",templet:function (data) {
                            if(data.loginState==2){
                                return "登陆成功";
                            }else if(data.loginState==3){
                                return "登陆失败";
                            }
                        }},
                    {field:"loginDate",title:"登录时间",align:"center"},
                    {field:"trueName",title:"登录名称",align:"center"},
                    {field:"account",title:"登录账号",align:"center"},
                    {field:"",title:"操作",align:"center",toolbar:"#button_caozuo"}
                ]]
            })
        }

        table.on('tool(demoTable)',function (obj) {
            var event = obj.event;
            if(event == "deleteTable") {
                layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
                    $.ajax({
                        url:"/login/deleteLoginRecord",
                        data:{'id':obj.data.id},
                        type:"post",
                        dataType:"json",
                        success:function (data) {
                            layer.msg("删除成功");
                            getTable('','');
                        }
                    })
                    layer.close(index);
                })
            }
        })

        function getTime(){
            var date=new Date();
            var year=date.getFullYear();
            var month=date.getMonth()+1;
            var day=date.getDate();
            var hour=date.getHours();
            var minute=date.getMinutes();
            var second=date.getSeconds();
            var dateStr = year+"-"+zeroFilling(month)+"-"+zeroFilling(day)+" "+zeroFilling(hour)+":"+zeroFilling(minute)+":"+zeroFilling(second);
            return dateStr;
        }
        function zeroFilling(data){
            if(data<10){
                data="0"+data;
            }
            return data;
        }


    })

</script>
</body>
</html>